package models

import (
	"gorm.io/gorm"
	"learn-server/basic/config"
	"time"
)

type Order struct {
	Id          uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	OrderSn     string         `gorm:"column:order_sn;type:varchar(255);comment:订单编号;not null;" json:"order_sn"` // 订单编号
	UserId      uint           `gorm:"column:user_id;type:bigint UNSIGNED;not null;default:0;" json:"user_id"`
	ClassId     uint           `gorm:"column:class_id;type:bigint UNSIGNED;not null;default:0;" json:"class_id"`
	OrderPrice  uint           `gorm:"column:order_price;type:int UNSIGNED;not null;default:0;" json:"order_price"`
	OrderStatus uint           `gorm:"column:order_status;type:int UNSIGNED;comment:订单状态：1：已完成 2：已退款 3：已支付 4：未支付;not null;default:0;" json:"order_status"` // 订单状态：1：已完成 2：已退款 3：已支付 4：未支付
	CreatedAt   time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt   time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (o *Order) TableName() string {
	return "order"
}
func (o *Order) CreateOrder() error {
	return config.DB.Create(&o).Error
}
func (o *Order) GetOrderInfo() error {
	return config.DB.Where("id = ?", o.Id).Find(&o).Error
}
func (o *Order) GetOrderDetail() error {
	return config.DB.Where("id = ?", o.Id).Find(&o).Error
}
